package com.haina.shop.mapper;

import com.github.pagehelper.Page;
import com.haina.shop.domain.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 48077
* @description 针对表【tz_order(订单表)】的数据库操作Mapper
* @createDate 2024-07-31 18:34:29
* @Entity com.haina.shop.domain.Order
*/
public interface OrderMapper extends BaseMapper<Order> {
    /**
     * 根据订单状态查询数量
     * @param status
     * @return
     */
    @Select("select count(*) from yami_shops.tz_order where status=#{status} and user_id=#{userId}")
    Integer selectListByStatus(@Param("status") Integer status,@Param("userId") Long userId);
    @Select("select * from yami_shops.tz_order where status=#{status} and user_id=#{userId} order by create_time desc")
    Page<Order> selectByStatus(@Param("status") Integer status, @Param("userId") Long userId);
    @Select("select * from yami_shops.tz_order where  user_id=#{userId} order by create_time desc")
    Page<Order> selectAll(Long userId);
    @Select("select * from yami_shops.tz_order where order_number=#{orderNumber}")
    Order getByOrderNum(String orderNumber);

    /**
     * 根据订单号获取订单
     * @param orderNumber
     * @return
     */
    @Select("select * from yami_shops.tz_order where user_id=#{userId} and order_number=#{orderNum}")
    Order selectByOrderNum(@Param("userId") Long userId,
                           @Param("orderNum") String orderNumber);

    /**
     * 根据订单号和当前用户id删除订单
     * @param userId
     * @param orderNumber
     * @return
     */
    @Delete("delete  from yami_shops.tz_order where user_id=#{userId} and order_number=#{orderNum}")
    int deleteByIdAndUserId(@Param("userId") Long userId,
                            @Param("orderNum") String orderNumber);
}




